package hn.cch.grammar.keyword;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;

public class AutoCloseDemo {

    public static void main(String[] args) {
        // interface Closeable extends AutoCloseable
        // try () {} 结构可以实现自动调用close()释放资源
        byte[] bytes = "0123456789".getBytes(StandardCharsets.UTF_8);
        try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes)) {
            byte[] byteArray = new byte[1024];
            int len = byteArrayInputStream.read(byteArray);
            System.out.printf("len=%d\n", len);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

}
